//#include "rud/ContainerAndImagePanels.h"
#include <stdafx.h>
#include <ParserDICOM.h>


class TLoadFiles: public QObject{
	Q_OBJECT
		public slots:
		void onQuit();
		void changeCurSize(unsigned int curByte, unsigned int total);
protected:	
	QMutex mutex;
	BOOLEAN isNeedTerminate;
	//void run();
public:
signals:	
	void startParsingSignal();
	void signalParseFile(const QString& , const QString & , const QString &);
	void signalLoaded(int curNumberOfFile,  int numberOfAllFiles, QString curFileName,
		unsigned int currentByte, unsigned int total, unsigned int currentByteAll, unsigned int totalAll);
	void signalEndFileParse();
	void signalEndLoading();
private:
	void emitSignalLoaded();
public slots:
	void startParsingSlot();
	void onEndParseFile();	
	void parseFile(const QString & path, const QString & params = "", const QString & filter = "");
public:		
	TLoadFiles();
	~TLoadFiles();
	void parse();
	void setDirList(QStringList dirs, QString filter = ""){this->dirs = dirs; this->filter = filter;};
	void setFilePath(QString filePath){ this->filePath = filePath;};
	void setIsNeedTerminate(BOOLEAN isNeedTerminate);		
	void startParsing();

	QString filter;
	QStringList files;
	int successfullLoaded;
	int numberOfAllFiles;
	int curNumberOfFile;		
	QString curFileName;
	unsigned int fullSize;
	unsigned int fullPrevSize;
	unsigned int AllSizes;		
	BOOLEAN getIsNeedTerminate();	
	void startLoading(const QString & path, const QString & params = "", const QString & filter = "");
	void startLoading();			
	//	void startParsing();
	QString filePath;	
	QStringList dirs;	
	int curByte;
	int total;
	ParserDICOM parserDICOM;
	BOOLEAN isEnd;
};

class TLoadFilesThread : public QThread{
	Q_OBJECT
public slots:
	void onEnd();
protected:
	void run();	
public:
	TLoadFiles * loadFiles;
	TLoadFilesThread();
	~TLoadFilesThread();
	void startParsing();
};

class TLoadFilesDialog : public QDialog{
	Q_OBJECT	
		public slots:
			void onOk();
			void onCancel();	
			void accept();
	public:	
	
	BOOLEAN noMessage;	
	TLoadFilesDialog(QStringList _dirs, QString _filter = "", QString _filePath = "");	
	~TLoadFilesDialog();
protected:
	void showEvent ( QShowEvent * event );	
	void timerEvent(QTimerEvent * event);
private:	
	int timer;
	TLoadFilesThread loadFilesThread;	
	QProgressBar progress;
	QProgressBar progressAll;	
	QPushButton ok;
	QVBoxLayout vl;	
	QVBoxLayout v2;	
	QVBoxLayout v3;	
	QVBoxLayout v4;	
	QHBoxLayout h0;		
	QHBoxLayout h1;		
	QHBoxLayout h2;		
	QHBoxLayout h3;		
	QPushButton cancel;
	QLabel label;
 
public slots:
	void repaintWidget( int curNumberOfFile, int numberOfAllFiles, QString curFileName, unsigned int currentByte, unsigned int total, unsigned int currentByteAll, unsigned int totalAll );
	void reject();
};

int removeFolder(QDir & dir);
void loadFromURL(QUrl url, const QString &filter = "", BOOLEAN noMessage = true);
void loadDicomFromPath(const QStringList & paths, const QString & params, const QString& filter);
QStringList getAllfilesFromSubDirs(const QString & filePath);